/* 
 * File:   Attribute.cpp
 * Author: H4314
 * 
 * Created on 3 avril 2012, 09:46
 */

#include "Attribute.h"

int Attribute::ATTRS = 0;

Attribute::Attribute(const string & name, const string & value)
: name(name), value(value)
{
    ATTRS++;
#ifdef SHOW_FREE
        cout << "ADD: ATTRIBUTE(" << name << ")" << endl;
#endif
}

Attribute::Attribute(const Attribute& orig) {
    ATTRS++;
#ifdef SHOW_FREE
        cout << "ADD: ATTRIBUTE(" << name << ")" << endl;
#endif
    this->name = orig.name;
    this->value = orig.value;
}

Attribute::~Attribute() {
    ATTRS--;
#ifdef SHOW_FREE
        cout << "DEL: ATTRIBUTE(" << name << ")" << endl;
#endif
}

void Attribute::CleanItUp(list<Attribute *> & attrList) {
    while(!attrList.empty())
    {
        delete attrList.back();
        attrList.pop_back();
    }
}

// Getters
const string & Attribute::getName() const {
    return name;
}

const string & Attribute::getValue() const {
    return value;
}

// Setters
void Attribute::setName(const string & newName) {
    this->name = newName;
}

void Attribute::setValue(const string & newValue) {
    this->value = newValue;
}

// Operators
ostream & operator<<(ostream & stream, const Attribute & attribute) {
    attribute.Print(stream);
    return stream;
}

void Attribute::Print(ostream & stream) const {
    stream << name << " = \"" << value << "\"";
}
